Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
The algosdk npm package is a JavaScript library for interacting with the Algorand blockchain. It provides tools for building applications on Algorand, including creating and managing accounts, sending transactions, and interacting with smart contracts.
Account Management
This feature allows you to create and manage Algorand accounts. The code sample demonstrates how to generate a new account and retrieve its address and mnemonic.
const algosdk = require('algosdk');
const account = algosdk.generateAccount();
console.log('Address:', account.addr);
console.log('Mnemonic:', algosdk.secretKeyToMnemonic(account.sk));
Transaction Handling
This feature enables the creation and submission of transactions on the Algorand blockchain. The code sample shows how to create a payment transaction, sign it, and send it to the network.
const algosdk = require('algosdk');
const algodClient = new algosdk.Algodv2(token, server, port);
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: senderAddress,
to: receiverAddress,
amount: 1000000,
suggestedParams: await algodClient.getTransactionParams().do()
});
const signedTxn = txn.signTxn(senderPrivateKey);
const sendTx = await algodClient.sendRawTransaction(signedTxn).do();
console.log('Transaction ID:', sendTx.txId);
Smart Contract Interaction
This feature allows interaction with Algorand smart contracts. The code sample demonstrates how to call a smart contract with arguments using a NoOp transaction.
const algosdk = require('algosdk');
const algodClient = new algosdk.Algodv2(token, server, port);
const appArgs = [algosdk.encodeUint64(123)];
const txn = algosdk.makeApplicationNoOpTxn(senderAddress, await algodClient.getTransactionParams().do(), appId, appArgs);
const signedTxn = txn.signTxn(senderPrivateKey);
const sendTx = await algodClient.sendRawTransaction(signedTxn).do();
console.log('Transaction ID:', sendTx.txId);
Web3.js is a JavaScript library for interacting with the Ethereum blockchain. It provides similar functionalities to algosdk, such as account management, transaction handling, and smart contract interaction, but is specific to Ethereum.
Ethers.js is another JavaScript library for Ethereum, offering a more lightweight and modular approach compared to web3.js. Like algosdk, it provides tools for managing accounts, sending transactions, and interacting with smart contracts, but is focused on the Ethereum ecosystem.
AlgoSDK is the official JavaScript library for communicating with the Algorand network. It's designed for modern browsers and Node.js.
$ npm install algosdk
This package provides TypeScript types, but you will need TypeScript version 4.2 or higher to use them properly.
Include a minified browser bundle directly in your HTML like so:
<script
src="https://unpkg.com/algosdk@v2.10.0/dist/browser/algosdk.min.js"
integrity="sha384-/nsSdRUItyaWG9aAQkugPs/yAyEaWwKsmRNCUk/TE7sN/iv3H+Iz1ZN4eNVFLV7E"
crossorigin="anonymous"
></script>
or
<script
src="https://cdn.jsdelivr.net/npm/algosdk@v2.10.0/dist/browser/algosdk.min.js"
integrity="sha384-/nsSdRUItyaWG9aAQkugPs/yAyEaWwKsmRNCUk/TE7sN/iv3H+Iz1ZN4eNVFLV7E"
crossorigin="anonymous"
></script>
Information about hosting the package for yourself, finding the browser bundles of previous versions, and computing the SRI hash is available here.
const token = 'Your algod API token';
const server = 'http://127.0.0.1';
const port = 8080;
const client = new algosdk.Algodv2(token, server, port);
(async () => {
console.log(await client.status().do());
})().catch((e) => {
console.log(e);
});
Documentation for this SDK is available here: https://algorand.github.io/js-algorand-sdk/. Additional resources are available on https://developer.algorand.org.
Running examples requires access to a running node. Follow the instructions in Algorand's developer resources to install a node on your computer.
As portions of the codebase are written in TypeScript, example files cannot be run directly using node
. Please refer to the instructions described in the examples/README.md file for more information regarding running the examples.
To build a new version of the library, run:
npm run build
To generate the documentation website, run:
npm run docs
The static website will be located in the docs/
directory.
We have two test suites: mocha tests in this repo, and the Algorand SDK test suite from https://github.com/algorand/algorand-sdk-testing.
To run the mocha tests in Node.js, run:
npm test
To run the SDK test suite in Node.js, run:
make docker-test
The test suites can also run in browsers. To do so, set the environment variable TEST_BROWSER
to
one of our supported browsers. Currently we support testing in chrome
and firefox
. When
TEST_BROWSER
is set, the mocha and SDK test suites will run in that browser.
For example, to run mocha tests in Chrome:
TEST_BROWSER=chrome npm test
And to run SDK tests in Firefox:
TEST_BROWSER=firefox make docker-test
This project enforces a modified version of the Airbnb code style.
We've setup linters and formatters to help catch errors and improve the development experience:
If using the Visual Studio Code editor with the recommended extensions, ESLint errors should be highlighted in red and the Prettier extension should format code on every save.
The linters and formatters listed above should run automatically on each commit to catch errors early and save CI running time.
js-algorand-sdk is licensed under an MIT license. See the LICENSE file for details.
FAQs
The official JavaScript SDK for Algorand
The npm package algosdk receives a total of 109,065 weekly downloads. As such, algosdk popularity was classified as popular.
We found that algosdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.